/*
 * AlarmUpdate.h
 *
 *  Created on: 2015-5-29
 *      Author: root
 */

#ifndef ALARMUPDATE_H_
#define ALARMUPDATE_H_
#include"PublicConfig.h"
#if USE_PUBLIC_ALARM
#include<set>
#include<map>
#include<string>
#include<time.h>
#include<string.h>
#include<stdint.h>
#include<sys/types.h>
#ifdef __MINGW32__
#include<_bsd_types.h>
#endif
///////////////////////////////////////////////////////////
typedef struct _THRESHOLD_INFO{
int fThreshodValue;//阀值单位ms
int nFrequency;	 //频次出现几次不报
int nCycle;			 //发送周期或检测周期
char sExtension[256];//扩展信息
}THRESHOLD_INFO;//存储默认阀值
typedef std::map<int,THRESHOLD_INFO> MAPTHRESHOLD;//策略ID,阀值
//typedef std::set<int> SETESSID;//平台ID
//typedef std::map<int,int>MAPESSINFO;//IP，平台，组ID对应策略ID(ID计算IP(IPID*10+0)(GROUPID*10+1)(PLANTID*10+2))

typedef struct _AlarmInfo{
u_short bjdm;//报警代码
u_short port;//报警端口
char    bjip[64];//报警IP
char    value[64];//报警值
bool operator < (struct _AlarmInfo const &other)const{
	if(strcmp(bjip, other.bjip)<0)
		return true;
	if(strcmp(bjip, other.bjip)==0){
		if(bjdm<other.bjdm)
			return true;
		if(bjdm==other.bjdm)
			return port<other.port;
	}
	return false;
}
}AlarmInfo;
typedef std::set<AlarmInfo> SETALARM;//告警队列
///////////////////////////////////////////////////////////
typedef struct _ALARMINFO{
long   ID;//报警ID
char   ip[64];//报警ip,兼容v6 以及非IP情况
char   bjdk[256];//url_id:url
int    jkzt;//报警级别
int    bjdm;//报警代码
char   bjz[256];//报警值
int    bjcs;//报警次数
//time_t scbjsj;//首次报警时间
bool operator < (struct _ALARMINFO const &other)const{
if(bjdm<other.bjdm){
	return true;
}else
if(bjdm==other.bjdm){
	if(strcmp(ip,other.ip)<0){
		return true;
	}else
	if(strcmp(ip,other.ip)==0){
//若都已ALL_开头认为相等
#if 1
        if(strncmp(bjdk,"ALL_",4)==0&&strncmp(other.bjdk,"ALL_",4)==0){
            return false;
        }else
#endif
		if(strcmp(bjdk,other.bjdk)<0){
			return true;
        }
	}
}
return false;
}
}ALARMINFO;
typedef std::set<ALARMINFO>SETALARMINFO;
//0CDN服务器报警
//1CDN交换机报警
//5CDN链路质量报警
//6IDC服务器报警
//7IDC交换机报警
//8IDC链路质量报警
//0正常 -1 执行失败 -2 连接失败
int PublicUpdateAlarm(SETALARMINFO alarminfo,const char*SQL,int alarmtype,int mysqltype);
//若成功则清除报警，blean强制清除
int PublicUpdateAlarmEx(SETALARMINFO&alarminfo,const char*SQL,int alarmtype,int mysqltype,int bClean);
//快速备份
int PublicUpdateAlarmFastBack(SETALARMINFO&alarminfo,const char*SQL,int mysqltype);
#endif
#endif /* ALARMUPDATE_H_ */
